<template>
    <div style="container">
        <mt-header title="历史红包">
            <router-link to="/redBag" slot="left">
                <mt-button icon="back">返回</mt-button>
            </router-link>
        </mt-header>
        <ul class="infinite-list redBagContainer" v-infinite-scroll="load" style="overflow:auto" infinite-scroll-disabled="close">
            <div class="redBox infinite-list-item" v-for="(item,index) in redBag" :key="index">
                <div class="gray">
                    <div class="black"></div>
                </div>
                <div class="imgBox"><img :src="item.shopUrl"></div>
                <div class="messageBox">
                    <p class="title" v-if="item.shopId!=0&&item.type!='activity'">{{item.shopName}}专享红包</p>
                    <p class="title" v-if="item.shopId!=0&&item.type=='activity'">{{item.shopName}}盲盒</p>
                    <p class="title" v-if="item.shopId==0">{{item.shopName}}</p>
                    <p>{{item.startTime}}到{{item.endTime}}</p></div>
                <div class="reductionBox">
                    <p class="use">￥{{item.reduction/100}}</p><p>满{{item.fullReduction/100}}可用</p>
                </div>
                <div></div>
                <div>
                    <p v-if="item.shopId!=0">仅用于指定商家</p>
                    <p v-if="item.shopId==0">可用于任何商家</p>
                </div>
                <div class="icon">
                    <img src="../images/已过期.svg"  v-if="item.tag==-1">
                    <img src="../images/已使用.svg"  v-if="item.tag==-2">
                </div>
            </div>
        </ul>
    </div>
</template>
<script>
    export default{
        data(){
            return{
                redBag:[],
                currentPage:0,
                size:5,
                close:false,
            }
        },
        methods:{
            load(){
                let tokenStr=window.sessionStorage.getItem("tokenStr");
                this.currentPage=this.currentPage+1;
                let postData={
                    currentPage:this.currentPage,
                    size:this.size,
                };
                this.getRequest('/redPaper/getHistoryRedParper',postData,tokenStr).then(response=>{
                    if(response.code==200){
                        let list=response.obj.data;
                        for(let i=0;i<list.length;i++){
                            list[i].startTime=list[i].startTime.replace(/T/," ");
                            list[i].endTime=list[i].endTime.replace(/T/," ");
                            list[i].startTime=list[i].startTime.slice(0,16);
                            list[i].endTime=list[i].endTime.slice(0,16);
                            list[i].shopUrl="/file"+list[i].shopUrl;
                            let index=list[i].redParperId.indexOf("_");
                            list[i].type=list[i].redParperId.slice(0,index);
                            this.redBag.push(list[i]);
                        }
                        if(this.redBag.length>=response.obj.all)
                            this.close=true;
                    }
                })
            },
        }
    }
</script>
<style lang="scss" scoped>
    @import 'mint-ui/lib/style.css';
    @import '../style/mixin';
    *{
        margin: 0;
        padding: 0;
    }
    .container{
        background-color:#f1f1f1;
        position: relative;
    }
    .redBagContainer{
        @include width-height(100%,93vh);
    }
    .gray{
        position: absolute;
        @include width-height(100%,7rem);
        z-index: 999;
        .black{
            @include width-height(100%,7rem);
            background-color:#ccc;
            position: absolute;
            top: 0;
            left: 0;
            opacity: 0.3;
            border-radius: 1.2rem;
            padding-bottom: 0.2rem;
            padding-top: 0.5rem;
            border-bottom: 2px solid #f1f1f1;
        }
    }
    .redBox{
        position: relative;
        @include width-height(100%,7rem);
        display: grid;
        grid-template-rows: 66.66% 33.33%;
        grid-template-columns: 15% 62% 23%;
        padding-top: 0.5rem;
        border-radius: 1.2rem;
        background-color: #fff;
        border-bottom: 2px solid #f1f1f1;
        padding-bottom: 0.2rem;
        margin-top: 0.2rem;
        .imgBox{
            text-align: center;
            img{
                @include width-height(50px,50px);
                margin-top: 0.5rem;
                border-radius: 0.3rem;
            }
        }
        .messageBox{
            .title{
                padding-top: 0.5rem;
                @include font-size-color(1.2rem,#000);
                font-weight: bold;
            }
            p{
                padding-top: 0.3rem;
            }
        }
        .reductionBox{
            text-align: center;
            position: relative;
            .use{
                padding-top: 0.7rem;
                @include font-size-color(1.8rem,rgba(231, 73, 25, 0.87));
                font-weight: bold;
            }
            .tip{
                display: inline;
                padding: 0.1rem 0.2rem 0.1rem 0.2rem;
                border-radius: 0.4rem;
                position: absolute;
                right: 0;
                top:-0.5rem;
                background-color: rgba(255, 219, 209, 0.87);
                @include font-size-color(0.8rem,rgba(231, 73, 25, 0.87));
            }
        }
        p{
            @include font-size-color(1rem,#666);
        }
        .icon{
            overflow:hidden;
            img{
                margin: -0.8rem 0 0 0.8rem;
                @include width-height(80px,80px);
            }
        }
    }
</style>
